//
//  Home_NavBar.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "Home_NavBar.h"

@interface Home_NavBar ()

//@property (nonatomic, strong) UIView *searchView;
//@property (nonatomic, strong) UIButton *scanBtn;
@property (nonatomic, strong) Home_navBar_MenuView *btn1View;
@property (nonatomic, strong) Home_navBar_MenuView *btn2View;

@end

@implementation Home_NavBar

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
//        self.searchView = [[UIView alloc] initWithFrame:CGRectMake(15, 9, ScreenW - 56 - 15, 36)];
//        self.searchView.backgroundColor = HexColor(0xffffff);
//        self.searchView.layer.masksToBounds = YES;
//        self.searchView.layer.cornerRadius = 6;
//        [self addSubview:self.searchView];
//
//        UIImageView *searchImgView = [[UIImageView alloc] initWithFrame:CGRectMake(6, 6, 24, 24)];
//        searchImgView.image = [UIImage imageNamed:@"icon_search"];
//        [self.searchView addSubview:searchImgView];
//
//        UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(searchImgView.nim_right + 10, 6, self.searchView.nim_width - (searchImgView.nim_right + 10), 24)];
//        titleLab.textColor = HexColor(0xDBDCE6);
//        titleLab.font = [UIFont systemFontOfSize:16];
//        titleLab.text = @"输入单号一键搜索";
//        [titleLab sizeToFit];
//        titleLab.nim_centerY = searchImgView.nim_centerY;
//        [self.searchView addSubview:titleLab];
//
//        UIButton *searchBtn = [[UIButton alloc] initWithFrame:self.searchView.frame];
//        [searchBtn addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:searchBtn];
//
//        self.scanBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.searchView.nim_right + 10, self.searchView.nim_top, 36, 36)];
//        self.scanBtn.backgroundColor = HexColorA(0xffffff, 0.2);
//        self.scanBtn.layer.masksToBounds = YES;
//        self.scanBtn.layer.cornerRadius = 6;
//        [self.scanBtn setImage:[UIImage imageNamed:@"icon_qr"] forState:0];
//        [self.scanBtn addTarget:self action:@selector(scanClick) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:self.scanBtn];
        
        CGFloat menuW = (ScreenW - 30) * 0.5;
        CGFloat menuH = 61;

        self.btn1View = [[Home_navBar_MenuView alloc] initWithFrame:CGRectMake(15, 24, menuW, menuH)];
        self.btn1View.iconUrl = @"icon_home_mytask";
        self.btn1View.titleText = @"我的任务";
        __weak_self;
        self.btn1View.clickBlock = ^{
            if (weakself.taskBlock) {
                weakself.taskBlock();
            }
        };
        [self addSubview:self.btn1View];

        self.btn2View = [[Home_navBar_MenuView alloc] initWithFrame:CGRectMake(self.btn1View.nim_right, 24, menuW, menuH)];
        self.btn2View.iconUrl = @"icon_home_lookboard";
        self.btn2View.titleText = @"系统看板";
        self.btn2View.clickBlock = ^{
            if (weakself.lookBoardBlock) {
                weakself.lookBoardBlock();
            }
        };
        [self addSubview:self.btn2View];
//
//        self.storageBtn = [[Home_navBar_MenuView alloc] initWithFrame:CGRectMake(self.packageBtn.nim_right, self.searchView.nim_bottom + 24, menuW, menuH)];
//        self.storageBtn.iconUrl = @"icon_home_wms";
//        self.storageBtn.titleText = @"库存查询";
//        self.storageBtn.clickBlock = ^{
//            if (weakself.storageBlock) {
//                weakself.storageBlock();
//            }
//        };
//        [self addSubview:self.storageBtn];
//
//        self.systemBoardBtn = [[Home_navBar_MenuView alloc] initWithFrame:CGRectMake(self.storageBtn.nim_right, self.searchView.nim_bottom + 24, menuW, menuH)];
//        self.systemBoardBtn.iconUrl = @"icon_home_statistics";
//        self.systemBoardBtn.titleText = @"系统看板";
//        self.systemBoardBtn.clickBlock = ^{
//            if (weakself.boardBlock) {
//                weakself.boardBlock();
//            }
//        };
//        [self addSubview:self.systemBoardBtn];
    }
    return self;
}

- (void)searchClick {
    if (self.searchBlock) {
        self.searchBlock();
    }
}

- (void)scanClick {
    if (self.scanBlock) {
        self.scanBlock();
    }
}

@end

@interface Home_navBar_MenuView ()

@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *clickBtn;

@end

@implementation Home_navBar_MenuView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 40) * 0.5, 0, 40, 40)];
        [self addSubview:self.iconImgView];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, self.iconImgView.nim_bottom + 6, frame.size.width, 15)];
        self.titleLab.textColor = HexColor(0xffffff);
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.titleLab];
        
        self.clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self.clickBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.clickBtn];
    }
    return self;
}

- (void)btnClick {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

-(void)setIconUrl:(NSString *)iconUrl {
    _iconUrl = iconUrl;
    self.iconImgView.image = [UIImage imageNamed:iconUrl];
}

-(void)setTitleText:(NSString *)titleText {
    _titleText = titleText;
    self.titleLab.text = titleText;
}

@end
